import 'package:flutter/material.dart';

import '../common/common.dart';

class DefaultFormField extends StatelessWidget {
  final FocusNode? focusNode;
  final TextEditingController? textEditingController;
  final int? minLines;
  final int? maxLength;
  final int? maxLines;
  final double scrollPadding;
  final String? msg;
  final String? hintText;
  final TextStyle? style;
  final TextInputAction? textInputAction;
  final TextStyle? hintStyle;
  String? errorText;
  final Function(String)? onChange;

  DefaultFormField(
      {super.key,
      this.focusNode,
      this.textEditingController,
      this.minLines = 1,
      this.maxLength,
      this.maxLines = 1,
      this.scrollPadding = 0,
      this.msg = '',
      this.errorText = '',
      this.hintText,
      this.textInputAction,
      this.style,
      this.hintStyle,
      this.onChange});

  @override
  Widget build(BuildContext context) {
    return TextFormField(
      focusNode: focusNode,
      style: style,
      controller: textEditingController,
      minLines: minLines,
      maxLength: maxLength,
      maxLines: maxLines,
      textInputAction: textInputAction,
      decoration: InputDecoration(
        hintText: hintText,
        hintStyle:
            (hintStyle ?? style)?.copyWith(color: Styles.textTranslucentColor),
        filled: true,
        fillColor: Styles.lightColor,
        enabledBorder: enabledBorder(),
        focusedBorder: focusedBorder(),
      ),
      scrollPadding: EdgeInsets.only(bottom: scrollPadding),
      onChanged: onChange,
    );
  }
}

InputBorder enabledBorder() {
  return const OutlineInputBorder(
    borderSide: BorderSide(
      width: 1,
      color: Styles.transparent,
    ),
    borderRadius: BorderRadius.all(Radius.circular(8)),
  );
}

InputBorder focusedBorder() {
  return const OutlineInputBorder(
    borderSide: BorderSide(
      width: 1,
      color: Styles.transparent,
    ),
    borderRadius: BorderRadius.all(Radius.circular(8)),
  );
}
